package org.shan.security.oaserver.controller;

import org.shan.security.oaserver.pojo.MlnxUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by amanda.shan on 2019/3/10.
 */
@RestController
public class SecrityController {

    private static final Logger log = LoggerFactory.getLogger(SecrityController.class);

    @GetMapping("/data")
    public MlnxUserInfo getUser(Authentication authentication) {
        log.info("resource: user {}", authentication);

        MlnxUserInfo userInfo = null;

        UserDetails details = (UserDetails) authentication.getPrincipal();
        if (details != null){
            userInfo = new MlnxUserInfo();
            userInfo.setOpenId("1");
            userInfo.setUsername(details.getUsername());
        }

        return userInfo;
    }
}
